package zookeeper.controller;

import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import zookeeper.service.ZookeeperService;

import javax.annotation.Resource;

/**
 * @program: check-repetition
 * @description:
 * @author: hjk
 * @create: 2021-07-14 17:22
 **/
@RestController
public class ZkController {

    @Resource
    private ZookeeperService zookeeperService ;

    @ApiOperation(value="是否递归删除节点")
    @GetMapping("/sss")
    public String sss () throws InterruptedException {
        String name = Thread.currentThread().getName();
        boolean lock = zookeeperService.lock("order");
        System.out.println(name + " 获取锁" + lock);
        Thread.sleep(5 * 1000);
        boolean order = zookeeperService.unLock("order");
        System.out.println(name + " 释放锁" + order);
        return "success";
    }
}
